using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using ChuanPlus.FormControl;
using DevExpress.XtraBars.Ribbon;
using DevExpress.XtraBars;

namespace ChuanPlus
{
    public partial class FormMain : DevExpress.XtraBars.Ribbon.RibbonForm
    {
        Users currentUser = null;
        Control currentControl = null;
        public FormMain()
        {
            InitializeComponent();
            
        }

        private void FormMain_Load(object sender, EventArgs e)
        {
            //DevExpress.LookAndFeel.UserLookAndFeel.Default.SetSkinStyle("Blue");
            
            ribAdmin.Visible = false;
        }

        #region Tab Staff

        #region Group Order
        private void bbPurOrder_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            add(new ControlPurOrder(currentUser), bbPurOrder);

        }

        private void bbViewOrder_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            add(new ControlViewOrder(), bbViewOrder);

        }
        private void barButtonItem1_ItemClick(object sender, ItemClickEventArgs e)
        {
            add(new ControlManageRedInvoice(), bbRedInv);
        }

        #endregion
        #region Group Invoice
        private void bbNewInvoice_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            add(new ControlNewInvoice(currentUser), bbNewInvoice);
        }

        private void bbViewInvoice_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            add(new ControlViewInvoice(), bbViewInvoice);
        }
        #endregion
        #region Group Product
        private void bbProduct_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            add(new ControlProduct(), bbProduct);
        }

        private void bbProduction_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            add(new ControlProduction(), bbProduction);
        }

        private void bbStockCard_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            add(new ControlStockCard(), bbStockCard);
        }

        private void bbWarehouse_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
          //  add(new ControlWarehouse(), bbWarehouse);
        }
        private void bbViewProduction_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            add(new ControlViewProduction(), bbViewProduction);
        }
        #endregion
        #region Group Customer
        private void bbCustomer_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            add(new ControlCustomer(), bbCustomer);
        }

        private void bbDebtor_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            add(new ControlDebtor(), bbDebtor);
        }
        private void bbReceiptVoucher_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            add(new ControlReceiptVoucher(currentUser), bbReceiptVoucher);
        }
        #endregion
        #region Group Supplier
        private void bbSupplier_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            add(new ControlSupplier(), bbSupplier);
        }

        private void bbDebt_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            //add(new ControlDebt(), bbDebt);
        }
        private void bbReceipt_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            add(new ControlReceipt(currentUser), bbReceipt);
        }
        #endregion
        #region Group Rejection
        private void bbRejection_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            add(new ControlRejection(), bbRejection);

        }
        private void bbViewRejection_ItemClick(object sender, ItemClickEventArgs e)
        {
            add(new ControlViewRejection(), bbViewRejection);
        }
        #endregion
        #region Group sample
        private void bbTakeSample_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            add(new ControlNewSample(), bbTakeSample);
        }
        private void bbView_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            add(new ControlViewSample(), bbView);
        }
        #endregion
        #region Request
        private void bbNewRequest_ItemClick(object sender, ItemClickEventArgs e)
        {
            add(new ControlNewRequest(), bbNewRequest);
        }

        private void bbViewRequest_ItemClick(object sender, ItemClickEventArgs e)
        {
            add(new ControlViewRequest(), bbViewRequest);
        }
        #endregion
        #region process
        private void bbProcess_ItemClick(object sender, ItemClickEventArgs e)
        {
            add(new ControlProcessData(),bbProcess);
        }
        #endregion
#endregion

        #region Tab Admin

        #region Group Modify
        private void bbAdminOrder_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            add(new ControlAdminOrder(), bbAdminOrder);
        }

        private void bbAdminInvoice_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            add(new ControlAdminInvoice(), bbAdminInvoice);
        }

        private void bbAdminProduct_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            add(new ControlAdminProduct(), bbAdminProduct);
        }
        #endregion
        #region Group Manage
        private void bbAdminManageUser_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            add(new ControlAdminManageUser(), bbAdminManageUser);
        }
        #endregion
        #region Report
        private void bbSaleReport_ItemClick(object sender, ItemClickEventArgs e)
        {
            add(new ControlSalesReport(),bbSaleReport);
        }
        #endregion
        #endregion

        // Add User Control Method
        public void add(Control control, BarButtonItem button)
        {
            button.Down = true;
            foreach (BarItem item in ribbon.Items)
            {
                if (item.GetType().Name == "BarButtonItem" && !item.Equals(button))
                {
                    ((BarButtonItem)item).Down = false;
                }
            }
            if (currentControl != null)
            {
                currentControl.Dispose();
                currentControl = null;
            }
            currentControl = control; 
            mainPanel.Controls.Clear();            
            mainPanel.Controls.Add(currentControl);
            GC.Collect();
            GC.WaitForPendingFinalizers();
        }

        private void FormMain_Shown(object sender, EventArgs e)
        {
            FormLogin frmlogin = new FormLogin();
            frmlogin.ShowDialog();
            if (frmlogin.authenticated && frmlogin.isAdmin)
            {
                currentUser = frmlogin.user;
                ribAdmin.Visible = true;

            }
            else if (!frmlogin.authenticated)
            {           
                this.Close();
                this.Dispose();
            }            
        }

        private void barSubItem2_ItemClick(object sender, ItemClickEventArgs e)
        {

        }

        

        












    }
       

     
    
}